package com.ginmeta.common.base;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;

/**
 * 表格分页数据
 * @author GinMeta
 */
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class PageResult implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 消息状态码
     */
    private int code;

    /**
     * 消息内容
     */
    private String msg;

    /**
     * 数据
     */
    private Data data;

    @Getter
    @Setter
    @AllArgsConstructor
    @NoArgsConstructor
    public static class Data {

        /**
         * 当前页
         */
        private long pageNumber;

        /**
         * 总记录数
         */
        private long total;

        /**
         * 列表数据
         */
        private List<?> rows;
    }
    /**
     * 分页
     *
     * @param list  列表数据
     * @param total 总记录数
     */
    public PageResult(List<?> list, long total, long pageNumber) {
        this.data = new Data(pageNumber, total, list);
    }

    public void setData(List<?> list, long total, long pageNumber) {
        this.data = new Data(pageNumber, total, list);
    }

}
